package com.mall.service.authority.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.model.domain.UmsRoleMenuRelation;
import com.mall.service.authority.mapper.UmsRoleMenuRelationMapper;
import com.mall.service.authority.service.UmsRoleMenuRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UmsRoleMenuRelationServiceImpl extends ServiceImpl<UmsRoleMenuRelationMapper, UmsRoleMenuRelation> implements UmsRoleMenuRelationService {

    @Autowired
    private UmsRoleMenuRelationMapper umsRoleMenuRelationMapper;

    @Override
    public void allocMenu(Integer roleId, List<Integer> menuIds) {
        LambdaQueryWrapper<UmsRoleMenuRelation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UmsRoleMenuRelation::getRoleId,roleId);
        umsRoleMenuRelationMapper.delete(queryWrapper);

        for (Integer menuId : menuIds) {
            UmsRoleMenuRelation relation = new UmsRoleMenuRelation();
            relation.setRoleId(Long.valueOf(roleId));
            relation.setMenuId(Long.valueOf(menuId));
            this.save(relation);
        }
    }
}
